package com.liella.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liella.entity.File;
import com.liella.mapper.FileDao;
import com.liella.service.RedisService;
import com.liella.service.VedioService;
import com.liella.utils.FastDFSUtil;
import com.liella.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * 用户业务接口实现类
 *
 * @author  liyuu
 * @date 2022/12/05 15:32
 **/
@Service
public class VedioServiceImpl extends ServiceImpl<FileDao, File> implements VedioService {


    @Autowired
    private FastDFSUtil fastDFSUtil;


    @Autowired
    private RedisService redisService;



    @Override
    public String getFileMD5(MultipartFile file) throws Exception {
        return MD5Util.getFileMD5(file);
    }

    @Override
    public String uploadFileBySlices(MultipartFile slice, String fileMD5, Integer sliceNo, Integer totalSliceNo) throws Exception {
//        File dbFileMD5 = fileDao.getFileByMD5(fileMD5);
//        if(dbFileMD5 != null){
//            return dbFileMD5.getUrl();
//        }
//        Integer integer = fastDFSUtil.convertFileToSlices(slice);
//        totalSliceNo =integer;
//        sliceNo = 1;
//        String url = fastDFSUtil.uploadFileBySlices(slice, fileMD5, sliceNo, totalSliceNo);
//        if(!StringUtil.isNullOrEmpty(url)){
//            dbFileMD5 = new File();
//            dbFileMD5.setCreateTime(new Date());
//            dbFileMD5.setMd5(fileMD5);
//            dbFileMD5.setUrl(url);
//            dbFileMD5.setType(fastDFSUtil.getFileType(slice));
//            fileDao.addFile(dbFileMD5);
//        }
        String url = fastDFSUtil.uploadCommonFile(slice);
        return url;
    }

    @Override
    public String uploadVedio(MultipartFile slice) throws Exception {
        String url = fastDFSUtil.uploadCommonFile(slice);
        Assert.notNull(url,"上传失败");
        return url;
    }


}